﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{

    public class YCAFS20Data : BaseFunction
    {
        
        public YCAFS20Data()
            : base()
        {

        }
        public YCAFS20Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetWASTAMM(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "WASTAMM";
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "select * from icc_fsegroe "
                   ;
                
                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    //byte[] b;
                    //string value;
                    //foreach (DataRow dw in Result.Tables[TableName].Rows)
                    //{
                    //    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["customer"].ToString().Trim());
                    //    value = Encoding.GetEncoding("gb2312").GetString(b);
                    //    dw["customer"] = value;
                    //    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["PROVINCE"].ToString().Trim());
                    //    value = Encoding.GetEncoding("gb2312").GetString(b);
                    //    dw["PROVINCE"] = value;
                    //    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["ENDCUSTOMER"].ToString().Trim());
                    //    value = Encoding.GetEncoding("gb2312").GetString(b);
                    //    dw["ENDCUSTOMER"] = value;
                    //    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["COLOR"].ToString().Trim());
                    //    value = Encoding.GetEncoding("gb2312").GetString(b);
                    //    dw["COLOR"] = value;
                    //}
                }
                
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public void INSERTDATA(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "WASTAMM";
            string MANDANT = dwABPOS["MANDANT"].ToString();
            string SZGRP = dwABPOS["SZGRP"].ToString();
            string SZ = dwABPOS["SZ"].ToString();
            string DESCR = dwABPOS["DESCR"].ToString();
            string INTERFACE1 = dwABPOS["INTERFACE1"].ToString();
            string INTERFACE2 = dwABPOS["INTERFACE2"].ToString();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "INSERT INTO icc_fsegroe "
                    + " SELECT '" + MANDANT + "','" + SZGRP + "','" + SZ + "','" + DESCR + "','" + INTERFACE1 + "','" + INTERFACE2 + "' FROM DUAL  "
                   ;

                Result = Connect2Proxy(orlReadCommand);                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void UPDATEDATA(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "WASTAMM";
            string MANDANT = dwABPOS["MANDANT"].ToString();
            string SZGRP = dwABPOS["SZGRP"].ToString();
            string SZ = dwABPOS["SZ"].ToString();
            string DESCR = dwABPOS["DESCR"].ToString();
            string INTERFACE1 = dwABPOS["INTERFACE1"].ToString();
            string INTERFACE2 = dwABPOS["INTERFACE2"].ToString();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "UPDATE icc_fsegroe SET DESCR = '" + DESCR + "',INTERFACE1='" + INTERFACE1 + "',INTERFACE2='" + INTERFACE2 + "' "
                    + " WHERE MANDANT = '" + MANDANT + "' AND SZGRP = '" + SZGRP + "' AND SZ = '" + SZ + "'  "
                   ;

                Result = Connect2Proxy(orlReadCommand);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void DELETEDATA(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "WASTAMM";
            string MANDANT = dwABPOS["MANDANT"].ToString();
            string SZGRP = dwABPOS["SZGRP"].ToString();
            string SZ = dwABPOS["SZ"].ToString();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "DELETE icc_fsegroe "
                    + " WHERE MANDANT = '" + MANDANT + "' AND SZGRP = '" + SZGRP + "' AND SZ = '" + SZ + "'  "
                   ;

                Result = Connect2Proxy(orlReadCommand);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public DataSet BuildYCAFS20Data(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetWASTAMM(dwUI);
                setReturn.Merge(setResult);                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}